﻿using MangoMes.Commont.Domain.RBACs;
using MangoMes.Commont.DTOs;
using MangoMes.Commont.Infrastructures.Interfaces;
using MediatR;

namespace RBAC.Write.API.Applications.PermissionsFiles
{
    public class CaeteperHander : IRequestHandler<Createpercommand, ResultsDTO>
    {
        private readonly IBateRepository<Permissions> bate;

        public CaeteperHander(IBateRepository<Permissions> bate)
        {
            this.bate = bate;
        }

        public async Task<ResultsDTO> Handle(Createpercommand request, CancellationToken cancellationToken)
        {
            ResultsDTO res=new ResultsDTO() { Code=0};
            Permissions per = new Permissions();
            per.PermissionsUrl = request.PermissionsUrl;
            per.PermissionsName = request.PermissionsName;
            string conn = "server=112.124.69.237;port=3306;uid=root;pwd=No6123666;database=MangoMesDB";
            string str = "insert into permissions values (@PermissionsId,@PermissionsName,@PermissionsUrl,@State)";
            res.Code = await bate.Add(str, per, conn);

            //Permissions per = new Permissions();
            //per.PermissionsId = request.PermissionsId;
            //per.PermissionsName = request.PermissionsName;
            //string conn = "server=112.124.69.237;port=3306;uid=root;pwd=No6123666;database=MangoMesDB";
            //string str = "select * FROM permissions";
            //var a = bate.GetAll(str, per, conn).ToList();
            return res;
        }
    }
}
